<template>
  <div class="home-header">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>活动管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar :src="userInfo.portrait"></el-avatar>
        <!-- <i class="el-icon-arrow-down el-icon--right"></i> -->
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item icon="el-icon-plus">{{ userInfo.userName }}</el-dropdown-item>
        <el-dropdown-item icon="el-icon-plus" @click.native="logOut">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>

</template>

<script>
import { UserInfo } from '@/services/user';

export default {
  created() {
    this.loadUserInfo();
  },
  data() {
    return {
      userInfo: {
        userName: '管理员',
        portrait: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
      },
    };
  },
  methods: {
    async loadUserInfo() {
      const { data } = await UserInfo();
      this.userInfo = data.content;
    },
    logOut() {
      this.$confirm('是否登出该账户?', '退出', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$message({
          type: 'success',
          message: '登出成功!',
        });
        this.$store.commit('setUser', null);
        this.$router.push({ name: 'Login' });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消登出',
        });
      });
    },
  },
};
</script>

<style scoped>
.home-header {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #f8f9fb;
  padding: 0 20px;
}
</style>
